package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.Swiper;
import com.example.service.SwiperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/swiper")
public class SwiperController {

    @Autowired
    private SwiperService swiperService;

    @GetMapping
    public Result<Result.ResponseData<List<Swiper>>> getSwiper() {
        // 查询轮播图数据（最多5条）
        List<Swiper> swiperList = swiperService.getValidSwiper();

        // 构建响应体（code=1000，msg=success，data=轮播图列表）
        Result.ResponseData<List<Swiper>> responseData = new Result.ResponseData<>();
        responseData.setCode(1000);
        responseData.setMsg("success");
        responseData.setData(swiperList);

        // 用Result包装并返回
        return Result.success(responseData);
    }
}